//
// Created by zhouyi on 2019/9/10.
//
#include <stdio.h>
#include <stdlib.h>

int main() {
    // 给初始化的指针赋值为NULL，free之后置为NULL
    int *pInt = NULL;

    // 通用指针 void*
    int n = 100;
    char c;
    short s;

    int *ptr_n = &n;
    char *ptr_c = &c;
    short *ptr_s = &s;

    // 把一个整型指针转化成一个通用指针，地址不会改变，但是类型信息丢失
    printf("ptr_n address %p \n", ptr_n);
    void *ptr_void = ptr_n;
    printf("ptr_void address %p \n", ptr_void);

    int *ptr_n_1 = (int *) ptr_void;
    printf("ptr_n_1 address %d \n", *ptr_n_1);
    printf("size of int %lu \n", sizeof(int));
    printf("ptr_n_1 %p \n", ptr_n_1);
    printf("ptr_n_1 %p \n", ptr_n_1 + 1);
    printf("ptr_n_1 %p \n", ptr_n_1 + 2);
    printf("==========================================\n");


    void *v = (void *) 10;
    printf("size of void %lu \n", sizeof(void));
    printf("void_ %p \n", v);
    printf("void_ %p \n", v + 1);
    printf("void_ %p \n", v + 2);


    printf("==========================================\n");


    int array[] = { 10, 20, 30, 40, 50 };
    int *ptr_array = array;
    printf(" int array p %p \n", array);
    printf(" &int array p %p \n", &array);
    printf(" int array+1 %p \n", array + 1);
    // 偏移了数组的array数组的类型长度
    printf(" int array size %lu\n", sizeof(array));
    printf(" &int array+1 %p \n", &array + 1);
//    int (*ptr_array)[5] = &array;

}